<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
<html>
<title>Bloomberg Development Environment</title>
<html>
<pre>
// Copyright 2021-2023 Bloomberg Finance L.P.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// bmqpi_dtspan.h                                                     -*-C++-*-
#ifndef INCLUDED_BMQPI_DTSPAN
#define INCLUDED_BMQPI_DTSPAN

//@PURPOSE: Provide an interface representing a span of a distributed trace.
//
//@CLASSES:
//  bmqpi::DTSpan: Interface for a span of a distributed trace.
//  bmqpi::DTSpan::Baggage: A set of key-values used to describe a &#39;DTSpan&#39;.
//
//@DESCRIPTION:
// &#39;bmqpi::DTSpan&#39; is a pure interface representing a node within a distributed
// trace graph (which forms a DAG with edges as invocations).
//
// &#39;bmqpi::DTSpan::Baggage&#39; represents a set of key-values used to describe
// metadata belonging to a &#39;DTSpan&#39;. The phrase &quot;baggage&quot; is borrowed from the
// OpenTelemetry standard&#39;s terminology.

// BMQ
#include &lt;bmqscm_version.h&gt;

// BDE
#include &lt;bsl_unordered_map.h&gt;
#include &lt;bsl_string.h&gt;
#include &lt;bsl_string_view.h&gt;
#include &lt;bslma_allocator.h&gt;

namespace BloombergLP {
namespace bmqpi {

                                // ============
                                // class DTSpan
                                // ============

class DTSpan {
    // A pure interface for representing a span of a distributed trace.

  public:
    // PUBLIC CREATORS
    virtual ~DTSpan();
        // Destructor

    // PUBLIC ACCESSORS
    virtual bsl::string_view operation() const = 0;
        // Returns the name of the operation that this &#39;DTSpan&#39; represents.

                               // =============
                               // class Baggage
                               // =============


    // PUBLIC INNER CLASSES
    class Baggage BSLS_KEYWORD_FINAL {
        // A set of key-values used to describe a &#39;DTSpan&#39;.

      private:
        // PRIVATE TYPEDEFS
        typedef bsl::unordered_map&lt;bsl::string, bsl::string&gt; MapType;

        // PRIVATE DATA
        MapType d_data;

      public:
        // PUBLIC TYPES
        typedef MapType::const_iterator const_iterator;

        // PUBLIC CREATORS
        Baggage(bslma::Allocator *allocator = 0);

        // PUBLIC ACCESSORS
        const_iterator begin() const;
            // Returns a const-iterator used to iterate over key-values.

        const_iterator end() const;
            // Returns a const-iterator representing the end of key-values.

        bool has(const bsl::string&amp; key) const;
            // Returns whether this object holds a value associated with the
            // specified &#39;key&#39;.

        bsl::string_view get(const bsl::string&amp;      key,
                             const bsl::string_view&amp; dflt = &quot;&quot;) const;
            // Returns the value currently associated with &#39;key&#39;, or &#39;dflt&#39; if
            // no associated value is currently held.
            //
            // Beware that if &#39;key&#39; is not found and the returned &#39;string_view&#39;
            // outlives &#39;dflt&#39;, then the &#39;string_view&#39; will reference a
            // deallocated address.

        // PUBLIC MANIPULATORS
        void put(const bsl::string_view&amp; key, const bsl::string_view&amp; value);
            // Stores the specified &#39;value&#39; associated with the specified
            // &#39;key&#39;. Note that if such a &#39;key&#39; was already stored, then its
            // associated value will be replaced by the supplied one.

        bool erase(const bsl::string&amp; key);
            // Erases any value currently associated with &#39;key&#39;, and returns
            // whether any such value was previously held.
    };
};

}  // close package namespace
}  // close enterprise namespace

#endif
</pre>
</body>
</html>
